package com.tuniu.agents.impl.hotel;

import com.tuniu.agents.agent.AgentManagerGroup;
import com.tuniu.agents.common.agent.Recommender;
import com.tuniu.agents.common.handler.HotelStreamResponseHandler;
import com.tuniu.agents.common.service.itinerary.ItineraryService;
import com.tuniu.agents.impl.hotel.logger.HotelAgentLoggingService;
import com.tuniu.agents.message.MessageLogger;
import com.tuniu.agents.tools.hotel.tool.HotelDetail;
import com.tuniu.agents.tools.hotel.tool.NlowestPriceHotelList;
import com.tuniu.agents.tools.hotel.tool.PlowestPriceHotelList;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class HotelAgentConfig {

    public static final String HOTEL_TOOLS = "HotelAgent";
    public static final String HOTEL_POI_LIST_PARSE_DATA = "HOTEL_POI_LIST_PARSE_DATA";
    public static final String HOTEL_PACKAGE_LIST_PARSE_DATA = "HOTEL_PACKAGE_LIST_PARSE_DATA";

    @Autowired
    private ItineraryService itineraryService;

    @Bean(HOTEL_TOOLS)
    @SneakyThrows
    public HotelAgent hotelToolAgent(AgentManagerGroup agentManagerGroup) {
        MessageLogger logger = new MessageLogger(HotelAgentLoggingService.BEAN_NAME);
        return new HotelAgent(agentManagerGroup, HOTEL_TOOLS, "hotel-selection", logger,
                HotelDetail.TOOLNAME, NlowestPriceHotelList.TOOLNAME, PlowestPriceHotelList.TOOLNAME);
    }

    @Bean(HOTEL_POI_LIST_PARSE_DATA)
    @SneakyThrows
    public Recommender hotelPoiListParseData(AgentManagerGroup agentManagerGroup) {
        return new HotelRecommender(agentManagerGroup, HOTEL_POI_LIST_PARSE_DATA, "hotel-recommend", new HotelStreamResponseHandler(NlowestPriceHotelList.TOOLNAME, HOTEL_PACKAGE_LIST_PARSE_DATA, agentManagerGroup.getChatEnvironmentMemory(), agentManagerGroup.getMemoryManager(),agentManagerGroup.getMessageRender(),itineraryService));
    }

    @Bean(HOTEL_PACKAGE_LIST_PARSE_DATA)
    @SneakyThrows
    public Recommender hotelPackageListParseData(AgentManagerGroup agentManagerGroup) {
        return new HotelRecommender(agentManagerGroup, HOTEL_POI_LIST_PARSE_DATA, "hotel-recommend", new HotelStreamResponseHandler(PlowestPriceHotelList.TOOLNAME, HOTEL_PACKAGE_LIST_PARSE_DATA, agentManagerGroup.getChatEnvironmentMemory(), agentManagerGroup.getMemoryManager(), agentManagerGroup.getMessageRender(),itineraryService));
    }
}
